﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Caliburn.Micro.BikeWizard.Tests.Utils
{
    /// <summary>
    /// Waits for a specified number of seconds before firing a Completed event 
    /// </summary>
    public class Sleeper : IResult
    {
        #region Private Members
        private DispatcherTimer timer = new DispatcherTimer();
        #endregion

        #region Constructors
        public Sleeper(int secondsToSleep)
        {
            timer.Interval = new TimeSpan(0, 0, secondsToSleep);
            timer.Tick +=
                (sender, e) =>
                {
                    timer.Stop();
                    Completed(this, new ResultCompletionEventArgs() { Error = null, WasCancelled = false });
                };
        }
        #endregion

        #region IResult Implementation
        public void Execute(ActionExecutionContext context)
        {
            timer.Start();
        }

        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };
        #endregion
    }
}
